package com.bhs.sansonglogistics.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.utils.MyUtils;

public class ConfirmationDialog extends Dialog implements View.OnClickListener {

    private TextView mTvConfirm;
    private TextView mTvCancel;

    public ConfirmationDialog(@NonNull Context context) {
        super(context, R.style.MyBottomDialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_confirmation);
        Window window = getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        //保证按钮水平满屏
        attributes.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        attributes.width = MyUtils.getScreenWidth(getContext()) * 8 / 10;
        //设置显示位置
        window.setAttributes(attributes); //将属性设置给窗体
        initView();
    }

    private void initView() {
        mTvConfirm = findViewById(R.id.tv_confirm);
        mTvCancel = findViewById(R.id.tv_cancel);
        mTvConfirm.setOnClickListener(this);
        mTvCancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        dismiss();
        if (view.getId() == R.id.tv_confirm) {
            if (listener != null) {
                listener.onClick(view);
            }
        }
    }

    private MyClickListener listener;

    public void setMyClickListener(@Nullable MyClickListener l) {
        this.listener = l;
    }
}
